const USER_INFO_KEY = "User-Info";
import store from "@/store/index.js"
export default class User {

	/**
	 * 获取用户信息
	 */
	static getUserInfo() {
		let info = null;
		let ret = uni.getStorageSync(USER_INFO_KEY);
		if (ret && ret !== '') {
			info = JSON.parse(ret);
		} else {
			info = {
				userId: "",
				jobNo: "",
				orgId: "",
				orgName: "",
				userEmail: "",
				userRealName: "",
				userName: "",
				userMobile: "",
				headerImg: "",
				token: "",
				clientId:"",
				connectId:""
			};
		}
		return info;
	}
	
	static checkLogin(){
		let userInfo=this.getUserInfo();
		if(userInfo.userId!=''){
			store.commit('setHasLogin',true);
			store.commit('setUserInfo',userInfo);
			return true;
		}
		return false;
	}

	/**
	 * 设置用户信息
	 * @param {Object} model
	 */
	static setUserInfo(model) {
		uni.setStorageSync(USER_INFO_KEY, JSON.stringify(model));
		store.commit('setHasLogin',true);
		store.commit('setUserInfo',model);
		
	}

	/**
	 * 清除用户信息
	 */
	static clearUserInfo() {
		uni.setStorageSync(USER_INFO_KEY, '');
		store.commit('setHasLogin',false);
		store.commit('setUserInfo','');
	}

	static setPushClientInfo(clientId, connectId) {
		let userInfo = this.getUserInfo();
		
		if (!userInfo) {
			return false;
		} else {
			userInfo.clientId = clientId;
			userInfo.connectId = connectId;
			uni.setStorageSync(USER_INFO_KEY, JSON.stringify(userInfo));
		}
		return true;
	}


}
